﻿using Abp.Domain.Repositories;
using Abp.Domain.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SingleUserMall.Refunds
{
    public class RefundManager : DomainService
    {
        private readonly IRepository<Refund, long> _refundRepository;
        public RefundManager(IRepository<Refund, long> refundRepository)
        {
            _refundRepository = refundRepository;
        }

        public void Refund(Refund refund, string refundResult)
        {
            try
            {
                if (refund != null)
                {
                    var result = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(refundResult);
                    if (result.code == "SUCCESS")
                    {
                        switch (result.refund_status)
                        {
                            case "SUCCESS":
                                refund.Status = RefundStatus.Success;
                                break;
                            case "REFUNDCLOSE":
                                refund.Status = RefundStatus.Close;
                                break;
                            case "PROCESSING":
                                refund.Status = RefundStatus.Processing;
                                break;
                            case "CHANGE":
                                refund.Status = RefundStatus.Error;
                                break;
                            default: break;
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }
    }
}
